package tool

import (
	"time"
)

func GetDateYMDHIS(dateSep string, timeSep string, dateTimeSep string) string {
	now := time.Now()
	nowString := now.String()
	return nowString[0:4] + dateSep + nowString[5:7] + dateSep + nowString[8:10] + dateTimeSep + nowString[11:13] + timeSep + nowString[14:16] + timeSep + nowString[17:19]
}

func GetDateFromTimeYMDHIS(t time.Time, dateSep string, timeSep string, dateTimeSep string) string {
	nowString := t.String()
	return nowString[0:4] + dateSep + nowString[5:7] + dateSep + nowString[8:10] + dateTimeSep + nowString[11:13] + timeSep + nowString[14:16] + timeSep + nowString[17:19]
}

func GetDateYMD() string {
	now := time.Now()
	nowString := now.String()
	return nowString[0:4] + nowString[5:7] + nowString[8:10]
}

func GetDate(dateSep string) string {
	now := time.Now()
	nowString := now.String()
	return nowString[0:4] + dateSep + nowString[5:7] + dateSep + nowString[8:10]
}

func GetDateTime() string {
	return GetDateYMDHIS("-", ":", " ")
}

func TimeToString(time time.Time) string {
	return GetDateYMDHIS("-", ":", " ")
}

func GetTime(timeSep string) string {
	now := time.Now()
	nowString := now.String()
	return nowString[11:13] + timeSep + nowString[14:16] + timeSep + nowString[17:19]
}
func GetDateY() string {
	now := time.Now()
	nowString := now.String()
	return nowString[0:4]
}
func GetDateM() string {
	now := time.Now()
	nowString := now.String()
	return nowString[5:7]
}
func GetDateD() string {
	now := time.Now()
	nowString := now.String()
	return nowString[8:10]
}
func GetDayStart(cur time.Time) time.Time {
	newDate := time.Date(cur.Year(), cur.Month(), cur.Day(), 0, 0, 0, 0, time.UTC)
	return newDate
}

func GetDayEnd(cur time.Time) time.Time {
	newDate := time.Date(cur.Year(), cur.Month(), cur.Day(), 0, 0, 0, 0, time.UTC)
	newDate = newDate.AddDate(0, 0, 1)
	return newDate
}

func AddTime(cur time.Time, h int, i int, s int) time.Time {
	var prc, _ = time.LoadLocation("PRC")
	newDate := time.Date(cur.Year(), cur.Month(), cur.Day(), cur.Hour()+h, cur.Minute()+i, cur.Second()+s, 0, prc)
	return newDate
}
